package com.zhang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启swagger2
public class SwaggerConfig {

    //1.通过配置docket以配置Swagger具体参数
    @Bean
    public Docket docket1(Environment environment) {

        //(2)配置
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//a.配置文档信息
                .groupName("Lee")//b.给当前docket取一个分组名
                .enable(true) //c.是否开启swagger

                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zhang.controller"))// d.扫描哪些controller接口
                .paths(PathSelectors.ant("/user/login"))//e.过滤掉接口中的路径 (只留下/user/login)
                .build();
    }


    //2.配置文档信息
    private ApiInfo apiInfo() {
        //(1)配置联系人信息
        Contact contact = new Contact("联系人名字zhang", "http://xxx.xxx.com/联系人访问链接", "联系人邮箱a_15922678345@163.com");
        //(2)配置详细信息
        return new ApiInfo(
                "标题",
                "描述",
                "v1.0版本",
                "http://terms.service.url/组织链接",
                contact, // 联系人信息
                "Apach 2.0 许可",
                "许可链接",
                new ArrayList<>()// 扩展
        );
    }

}


